<?php
function list_dir($ordner, $akto) {

	mdbShowHeader();

	switch ($akto) {
	case'list':
		mdbShowUploadform();
		mdbShowFiles ($ordner);
		break;
	case'uploaded':
		echo "<h2>Upload erfolgreich..</h2>";
		mdbShowUploadform();
		mdbShowFiles ($ordner);
		break;
	default:
		echo $akto . " unbekannter Befehl !!! <br />";
	}
}

/**
 * Header
 */

function mdbShowHeader () {
	echo '<h1 align="center" class="mdb_outlinebox">CoverManager</h1>';
}

/**
 * Fileliste
 */

function mdbShowFiles($ordner) {
	global $mdbPrefs;
	global $mosConfig_live_site;
	echo '<h1 align="center" class="mdb_outlinebox">CoverListe</h1>';
	$sh_maxCols = $mdbPrefs[0]->cov_bilder_zeile;
	$verzeichnis = opendir($ordner);
	
	echo '<table border="1">';
	$sh_colCount = 0;
	echo '<tr>';
	while ($datei = readdir ($verzeichnis)) {
		if(eregi('.jpg',$datei)) {
			if ($datei != "." && $datei != "..") {
				if (!is_dir($ordner."/".$datei)) {
					$blah = getimagesize($ordner."/".$datei);
					$type = $blah['mime'];
					$tmpwidth = $blah[0];
					$tmpheight = $blah[1];
					$tmpDatei = substr($datei, 0, strlen($datei)-4);
					$tmpTitel = $tmpDatei . " / " . $tmpwidth . " X " . $tmpheight . " Pix.";
					echo '<td width="100px">' .
					'<a href="' . $mosConfig_live_site . '/' . $ordner . '/' . $datei . '" target="_blank">' . 
					'<img src="'.$ordner.'/'.$datei.'" width="100px" height="100px" alt="'.$tmpTitel.'" title="'.$tmpTitel.'" border="0"/></a>'.
					$tmpDatei . '<br />' .
					$tmpwidth . " X " . $tmpheight . " Pix.";
					echo '</td>';
					$sh_colCount++;
					if ($sh_colCount == $sh_maxCols) {
						echo '</tr><tr>';
						$sh_colCount = 0;	
					} else {
						
					}
				}
			}
		}
	}
	closedir($verzeichnis);
	echo '</tr></table>';
}

/**
 * Zeigt das Uploadformular
 */

function mdbShowUploadform () {
global $mosConfig_live_site;
?>
<hr />
<div class="mdb_outlinebox">
<h1 align="center">Upload</h1>
<form enctype="multipart/form-data" action="<?php echo $mosConfig_live_site . "/index.php?option=com_media_db&akto=covers_upload" ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="300000">
 <input name="operation" type="hidden" value="0">
Upload dieser Datei (<strong>jpg</strong>): <input name="userfile" type="file">------><input type="submit" value="Datei senden!">
</form>
</div>
<hr />
<?php
}
?>